<?php
require_once ("src/db/connectdatabase.php");
function loadCompareLoanDetail($arrcompare) {
	$con = new ConnectDB();
	
	$sql = "SELECT c.idcom, c.bankid, b.bankname, b.banklogo, c.idloanmaxi, c.amountloanmin, c.amountloanmax, c.salarypermounth, c.hinhthuctraluong, c.interrestrate, c.interrestrate2, c.typerate, c.timeloan, c.phitattoan, c.country, c.tttrchan, c.isbankphi FROM compareloanspersional AS c, banks AS b WHERE c.bankid=b.bankid AND c.idcom IN (".$arrcompare.")";
	return $con -> getvalueString($sql);
}
if(isset($_SESSION['arrcomparerate'])) {
	$arrcompare = $_SESSION['arrcomparerate'];
	$temp = "";
	for($i = 0; $i < count($arrcompare); $i++) {
		if($i == count($arrcompare)-1) {
			$temp .= $arrcompare[$i];
		} else {
			$temp .= $arrcompare[$i].',';
		}
	}
	$arrresultcompare = loadCompareLoanDetail($temp);
?>
<style>
.class-content-result-loading {
	position: fixed;
	height: 100%;
	width: 100%;
	background: #000;
	background: rgba(0,0,0,.8);
	z-index: 100;
	top: 0;
	left: 0;
	display: none;
}

.spanmarringleft {
	margin-left: 13px;
}

.colorbg {
	background: #F1F1F1;
}

.class-detail-title {
	width: 150px;
	font-weight: bold;
}

.compare-title {
	float: left;
	margin-left: 3px;
}

.product-details {
	float: left;
	margin-left: 3px;
}

dt, dd {
	float: left;
	height: 40px;
	padding-top: 12px;
}

dd {
	width: 200px;
	text-align: center;
	font-weight: bold;
	color: rgb(51, 51, 51);
	overflow: hidden;
}

.listwrapper {
	display: block;
	height: 350px;
	left: 123px;
	overflow-y: hidden;
	width: 865px;
}

.company {
	text-align: center;
	margin-bottom: 5px;
	line-height: 18px;
	padding: 5px 0px 10px;
	background-color: rgb(200, 225, 255);
	min-height: 40px;
	position: relative;
	border-radius: 5px 5px 5px 5px;
	box-shadow: 0px 1px 0px rgb(204, 204, 204);
	width: 200px;
	float: left;
	margin-left: 3px;
}

ol.productlist {
	margin-left: -76px;
	width: 865px;
	height: 350px;
	position: absolute;
	margin: 0px -76 auto;
}

ol li {
	float: left;
	list-style-type: none;	
}

.closeproduct {
	background-position: 0px -45px;
	height: 20px;
	position: absolute;
	right: 5px;
	top: 2px;
	width: 12px;
	cursor: pointer;
	background: url("<?php echo($host) ?>images/baseg.png") no-repeat scroll 0px 0px transparent;
}
</style>
<div class="class-content-result-loading"></div>
<div class="text12" style="margin: auto; width: 970px; height: 11px; margin-top: 11px; color: #0a8bd9;">
	<u><a href="<?php echo($host) ?>" class="text12" style="color: #0080d6;">Trang chủ</a></u>&gt; Tìm kiếm sản phẩm vay tốt nhất</div>
<div style="clear:both; height:15px;"></div>
<div style="width: 980px; clear: right;" class="class-content-company">
    <div style=" float:left; width:150px; margin-left:3px; height: 40px; text-align:center; padding-top: 20px;"></div>
    <!--<div class="company">
    	<span>
        	Name  Bank <br /> Loai hinh vay
        </span>
    	<a class="closeproduct" title="Xóa" value="123"></a>
    </div>-->
</div>
<div style="clear:both;"></div>
<div style="width: 980px;">
	<div style="width: 150px; float:left;">
        <dl class="compare-title" style="width: 150px;">
            <dt class="class-detail-title"><span class="spanmarringleft">Tổ chức cho vay</span></dt>
            <dt class="class-detail-title colorbg"><span class="spanmarringleft">Khoản vay tối đa</span></dt>
            <dt class="class-detail-title"><span class="spanmarringleft">Số tiền cho vay</span></dt>
            <dt class="class-detail-title colorbg"><span class="spanmarringleft">Lãi suất</span></dt>
            <dt class="class-detail-title"><span class="spanmarringleft">Thu nhập hàng tháng</span></dt>
            <dt class="class-detail-title colorbg"><span class="spanmarringleft">Hình thức trả lương</span></dt>
            <dt class="class-detail-title"><span class="spanmarringleft">Loại lãi suất</span></dt>
            <dt class="class-detail-title colorbg"><span class="spanmarringleft">Thời gian vay</span></dt>
            <dt class="class-detail-title"><span class="spanmarringleft">Phí tất toán</span></dt>
            <dt class="class-detail-title colorbg"><span class="spanmarringleft">Khu vực</span></dt>
            <dt class="class-detail-title"><span class="spanmarringleft">Tất toán trước hạn</span></dt>
            <dt class="class-detail-title colorbg"><span class="spanmarringleft">Nhà cung cấp</span></dt>
            <dt class="class-detail-title"><span class="spanmarringleft">Thanh toán hàng tháng</span></dt>
        </dl>
    </div>
    <div class="listwrapper" style="float:left;width: 830px;"><ol class="productlist"></ol></div>
    <div style="clear:both;"></div>
</div>
<script>
<?php
if(count($arrresultcompare) == 0) {
	echo('window.location = "'.$host.'so-sanh-vay.html";');
} 
?>
$(document).ready(function(e) {
<?php

	for($i = 0; $i < count($arrresultcompare); $i++) {
		$typerate = "Lãi suất dư nợ ban đầu";
		if($arrresultcompare[$i][11] == "1") {
			$typerate = "Lãi suất dư nợ giảm dần";
		}
		$cophi = "Không Phí";
		if($arrresultcompare[$i][15] == "cophi") {
			$cophi = "Có Phí";
		}
		
		$hinhthuctraluong = "Tiền mặt";
		if($arrresultcompare[$i][8] == "2") {
			$hinhthuctraluong = "Chuyển khoản";
		}
		
		$tochuc = "Ngân hàng";
		if($arrresultcompare[$i][16] == "phibank") {
			$tochuc = "Công Ty Tài Chính";
		}
		
		$stridloanmaxitemp = $arrresultcompare[$i][4];// cot khoan vay toi da
		$arridloanmaxi = explode(',', $stridloanmaxitemp);
		$nametemp = "";
		for($j = 0; $j < count($arridloanmaxi); $j++) {
			if($arridloanmaxi[$j] == "1") $nametemp .= "Dưới 6 lần thu nhập. "; else $nametemp .= "Trên 6 lần thu nhập. ";
		}
		
		$amountmin = changnumbermoney($arrresultcompare[$i][5]);
		$amountmax = changnumbermoney($arrresultcompare[$i][6]);
		$ratemin = $arrresultcompare[$i][9];
		$ratemax = $arrresultcompare[$i][10];
		
		$phihangthangmin = changnumbermoney(round(($arrresultcompare[$i][5] * $ratemin / 12 / 100), -3));
		$phihangthangmax = changnumbermoney(round(($arrresultcompare[$i][6] * $ratemax / 12 / 100), -3));
		
		echo("insertrow('".$arrresultcompare[$i][0]."', '".$arrresultcompare[$i][1]."', '".$arrresultcompare[$i][2]."', '".$arrresultcompare[$i][3]."', '".$nametemp."', '".$amountmin."', '".$amountmax."', '".$ratemin."', '".$ratemax."', '".$arrresultcompare[$i][7]."', '".$hinhthuctraluong."', '".$typerate."', '".$arrresultcompare[$i][12]."','".$arrresultcompare[$i][13]."','".$arrresultcompare[$i][14]."', '".$cophi."', '".$tochuc."', '".$phihangthangmin."', '".$phihangthangmax."');");
	}
?>
	
	function insertrow(id, bank, namebank, logo, vaytoida, sotien, sotien2, laisuat, laisuat2, thunhaphangthang, hinhthuctraluong, loailaisuat, timerate, phitattoan, contry, trchan, isbank, phihangthangmin, phihangthangmax) {
		htmlcom = '<div class="company"><span>'+namebank+'('+bank+')<br /></span><a class="closeproduct" title="Xóa" value="'+id+'"></a></div>';
		htmlcont = '<li id="product_'+id+'"><dl class="product-details" style="width: 200px;"><dd><img src="<?php echo($host) ?>'+logo+'" alt="'+namebank+'('+bank+')" title="'+namebank+'('+bank+')" height="36px" /></dd><dd class="colorbg">'+vaytoida+'</dd><dd>'+sotien+' VNĐ - ' + sotien2 + ' VNĐ</dd><dd class="colorbg">' + laisuat + '% - ' + laisuat2 + '%</dd><dd>' + thunhaphangthang + '</dd><dd class="colorbg">' + hinhthuctraluong + '</dd><dd>' + loailaisuat + '</dd><dd class="colorbg">' + timerate + ' năm</dd><dd>' +phitattoan + '</dd><dd class="colorbg">' + contry + '</dd><dd>' + trchan + '</dd><dd class="colorbg">' + isbank + '</dd><dd>' + phihangthangmin + ' VNĐ - ' + phihangthangmax + ' VNĐ</dd></dl></li>';
		
		$('.class-content-company').append(htmlcom).children(".company:last").hide().fadeIn(200);
		$('.productlist').append(htmlcont).children(".productlist li:last").hide().fadeIn(200);
	}
	
	$(document).on('click', '.closeproduct', function() {
		elem = $(this);
		value = elem.attr('value');
		$('.class-content-result-loading').show();
		$.ajax({
			type: "POST",
			url: "<?php echo($host) ?>control/ajaxcomparerate.php",
			data:{act: 'sscom', pr: 'del', idre: value},
			dataType: "json",
			success: function(response){
				$('.class-content-result-loading').hide();
				if(response == "ok") {
					elem.parent().fadeOut(300, function() {
						elem.parent().remove();
					});
					$('#product_'+value).fadeOut(300, function() {
						$('#product_'+value).remove();
					});
				}
			}
		});
	});
});
</script>
<?php
} else {
	echo("<script>window.location = '".$host."so-sanh-vay.html';</script>");
}
?>